package kyo;

public class Vt {
    static private Vt vt = null;

    private Vt() {}

    static public Vt getVt() {
        if (vt == null)
            vt = new Vt();
        return vt;
    }

    static public void p(String format, Object ... obj) {
        System.out.printf(format, obj);
    }

    // 绝对定位
    static public Vt gotoxy(int r, int c) {
        p("\033[%d;%dH", r, c);
        return getVt();
    }
    // 相对定位
    static public Vt move(VtDirect dir, int step) {
        p("\033[%d%c", step, dir.get());
        return getVt();
    }
    // 隐藏光标
    // 显示光标
    // 保存光标
    // 还原光标
    // 清屏
    // 清整行
    // 清除光标后面内容
    static public Vt cmd(VtCmd op) {
        p("\033[%s", op.get());
        return getVt();
    }

    // 随机前景颜色
    static public int color() {
        return (int)(Math.random() * 7 + 30);
    }

    // 颜色输出
    static public Vt out(String s, VtColor fColor,
                                boolean bold, VtColor bColor) {
        String cmd = "";

        if (fColor != null) {
            cmd += fColor.get();
        }
        if (bColor != null) {
            cmd += ";" + bColor.getBack();
        }
        if (bold) {
            cmd += ";1";
        }

        p("\033[%sm%s\033[0m", cmd, s);

        return getVt();
    }

    static public Vt out(String s, VtColor color, VtColor bColor) {
        return out(s, color, false, bColor);
    }

    static public Vt out(String s, VtColor color) {
        return out(s, color, false, null);
    }

    static public Vt out(String s, VtColor color, boolean bold) {
        return out(s, color, bold, null);
    }

    static public Vt outBack(String s, VtColor color) {
        return out(s, null, false, color);
    }
}
